package crypto

import (
	"crypto/elliptic"

	"github.com/tjfoc/gmsm/sm2"
	"github.com/tjfoc/gmsm/x509"
)

//Init 初始化
func Init(opts ...Option) {
	for _, opt := range opts {
		opt(&options)
	}
}

var csp *csProvider

type csProvider struct {
	KeyGenerators map[string]KeyGenerator
	//Signers   map[reflect.Type]Signer
	KeyImporters map[string]keyImporter
	//Verifiers map[reflect.Type]Verifier
	Hashers map[string]x509.Hash //支持的Hash算法
	Curves  map[string]elliptic.Curve
}

//默认初始化函数
func init() {
	//初始化支持的Hash算法
	hashers := map[string]x509.Hash{
		"MD5":    x509.MD5,
		"SHA1":   x509.SHA1,
		"SHA224": x509.SHA224,
		"SHA256": x509.SHA256,
		"SHA384": x509.SHA384,
		"SHA512": x509.SHA512,
		"SM3":    x509.SM3,
	}

	//生成器
	keyGnerators := map[string]KeyGenerator{
		"SM2":    &sm2KeyGenerator{sm2.P256Sm2()},
		"SM4":    &sm4KeyGenerator{},
		"ECDSA":  &ecdsaKeyGenerator{elliptic.P256()},
		"AES":    &aesKeyGenerator{32},
		"AES256": &aesKeyGenerator{32},
		"AES192": &aesKeyGenerator{24},
		"AES128": &aesKeyGenerator{16},
	}

	csp = &csProvider{KeyGenerators: keyGnerators, Hashers: hashers}

}
